package njiandan.mvc.core;

import njiandan.mvc.server.IServer;
import njiandan.mvc.server.ServerFactory;

public final class NjiandanMvc {
	
	private static IServer server;
	
	private static final NjiandanMvc me = new NjiandanMvc();
	
	private NjiandanMvc() {
	}
	
	public static NjiandanMvc me() {
		return me;
	}
	
	public static void start() {
		server = ServerFactory.getServer();
		server.start();
	}
	
	public static void start(String webAppDir, int port, String context, int scanIntervalSeconds) {
		server = ServerFactory.getServer(webAppDir, port, context, scanIntervalSeconds);
		server.start();
	}
	
	public static void stop() {
		server.stop();
	}
	
	public static void main(String[] args) {
		if (args == null || args.length == 0) {
			server = ServerFactory.getServer();
			server.start();
		}
		else {
			String webAppDir = args[0];
			int port = Integer.parseInt(args[1]);
			String context = args[2];
			int scanIntervalSeconds = Integer.parseInt(args[3]);
			server = ServerFactory.getServer(webAppDir, port, context, scanIntervalSeconds);
			server.start();
		}
	}
	
}
